﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using OpenSunTracker.RestClient;
using OpenSunTracker.RestClient.Extensions;

namespace OSTWin
{
    /// <summary>
    /// Interaction logic for ucSystem.xaml
    /// </summary>
    public partial class ucSystem : UserControl
    {
        public ucSystem()
        {
            InitializeComponent();
        }


        public OpenSunTrackerClient Client { get { return DataContext as OpenSunTrackerClient; } }

        private void btnReboot_Click(object sender, RoutedEventArgs e)
        {
            var actionUrl = Client.Url + "/system/reboot";
            try
            {
                var response = actionUrl.ExecuteReadRequest();
                Client.AddMessage("reboot (" + actionUrl + "): " + response.ReadAllText());
            }
            catch (Exception ex)
            {
                Client.AddMessage("error on reboot (" + actionUrl + "): " + ex.Message);
            }
        }

        private void btnNtpUpdate_Click(object sender, RoutedEventArgs e)
        {
            var actionUrl = Client.Url + "/ntp/update";
            try
            {
                var response = actionUrl.ExecuteReadRequest();
                Client.AddMessage("ntp-update (" + actionUrl + "): " + response.ReadAllText());
            }
            catch (Exception ex)
            {
                Client.AddMessage("error on ntp-update (" + actionUrl + "): " + ex.Message);
            }
        }

        //private void btnSetDate_Click(object sender, RoutedEventArgs e)
        //{
        //    var actionUrl = Client.Url + "/date";
        //    try
        //    {
        //        var response = actionUrl.ExecuteWriteRequestString("POST", txtDate.Text);
        //        Client.AddMessage("set-date (" + actionUrl + "): " + response.ReadAllText());
        //    }
        //    catch (Exception ex)
        //    {
        //        Client.AddMessage("error on set-date (" + actionUrl + "): " + ex.Message);
        //    }
        //}
    }
}
